package com.neuedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.entity.InterviewRecord;
import com.neuedu.mapper.InterviewRecordMapper;
import com.neuedu.service.InterviewRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;

/**
 * <p>
 * 模拟面试 服务实现类
 * </p>
 *
 * @author wangyu
 * @since 2025-09-12
 */
@Service
public class InterviewRecordServiceImpl extends ServiceImpl<InterviewRecordMapper, InterviewRecord> implements InterviewRecordService {

    @Override
    public InterviewRecord getRecord(Long login_id, String sessionId) {
        QueryWrapper<InterviewRecord> wrapper = new QueryWrapper<>();
        wrapper.eq("student_id", login_id)
                .eq("session_id", sessionId);
        return this.getOne(wrapper);
    }

    @Override
    public boolean delete(Long login_id, String sessionId) {
        UpdateWrapper<InterviewRecord> wrapper = new UpdateWrapper<>();
        wrapper.eq("student_id", login_id)
                .eq("session_id", sessionId);
        return this.remove(wrapper);
    }

    @Override
    public List<InterviewRecord> getRecordList(Long login_id) {
        QueryWrapper<InterviewRecord> wrapper = new QueryWrapper<>();
        wrapper.eq("student_id", login_id)
                .orderByDesc("id");
        IPage<InterviewRecord> page = this.page(new Page<>(1, 5), wrapper);
        return page.getRecords();
    }

    @Override
    public boolean save(Long login_id, String sessionId, String message, String result) {
        InterviewRecord record = new InterviewRecord(
                login_id,
                sessionId,
                message,
                LocalDate.now(),
                LocalTime.now(),
                result
        );
        return this.save(record);
    }
}
